package com.sduept.nwld.dataserver.manager.protection;

import com.sduept.core.dao.SuperDAO;
import com.sduept.nwld.dataserver.model.daily.OperationaRisk;
import com.sduept.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

@Service
public class OperationRiskManager {
	@Autowired
	SuperDAO dao;

	public List<OperationaRisk> getOperationaRisk(String start, String end) {
		Date s = DateUtil.getDateByString(start, DateUtil.pattern_ymdhms);
		Date e = DateUtil.getDateByString(end, DateUtil.pattern_ymdhms);
		Calendar cend = Calendar.getInstance();
		cend.setTime(e);
		cend.add(Calendar.DAY_OF_YEAR, 1);
		return dao.findByCondition(OperationaRisk.class,
				" reportTime between ? and ? order by workTime desc", s, cend.getTime());
		// return dao.findAll(OperationaRisk.class);
	}

	public List<OperationaRisk> getOperationaRisk() {
		return dao.findAll(OperationaRisk.class);
	}

	/**
	 * 单条编辑
	 */
	public void editUpdate(OperationaRisk selected) {
		if (selected != null) {
			dao.update(selected, OperationaRisk.class);
		}
	}

	/**
	 * 数据更新
	 */
	public void updateOperationaRisk(OperationaRisk selectRisk) {
		if (selectRisk != null) {
			try {
				dao.update(selectRisk, OperationaRisk.class); // update新的数据到这条Overhaulmag
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}

	/**
	 * 新增数据
	 * 
	 * @return
	 */
	public OperationaRisk creatOperationaRisk(OperationaRisk created) {
		if (created != null) {
			try {
				created = dao.create(created, OperationaRisk.class);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return created;
	}

	/**
	 * 单条删除
	 */
	public void delOperationaRisk(OperationaRisk selectRisk) {
		if (selectRisk != null) {
			try {
				dao.delete(selectRisk.getId(), OperationaRisk.class);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
}
